<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>

        <a-card>
          <div class="table-operator">
<!--                <a-button type="primary" icon="plus" @click="handleAdd" v-btnPermission="'bm_003_add_01'"-->
<!--                    >新增</a-button-->
<!--                >-->
            </div>
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :export-config="{
                        use: true,
                        select: '岗位责任书',
                        all: '岗位责任书'
                    }"
                :exportPermission="{ select: 'bm_003_exp_03', all: 'bm_003_exp_03' }"
                     :statistics-config="{ use: true,  countList, temp }"
            >
                <span slot="description" slot-scope="text">
                    <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
                </span>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="detailed(record)" v-btnPermission="'bm_003_loo_02'">查看</a>
                      <a @click="addEdit(record, 1)" v-if="record.redoExamine === 1&&record.auditStatus == 'PAST'&&hideBuquBtn()">补录</a>
                    <a v-if="(record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED')&&hideBuquBtn()" v-btnPermission="'bm_003_edi_01'">
                        <a @click="addEdit(record)">编辑</a>
                    </a>
                    <!-- <a v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'SUBMITTED'" v-btnPermission="'bm_003_del_03'">
                        <a @click="deleteDraft(record)">删除</a>
                    </a> -->
    
              <a @click="handleApproveDetail(record)" v-if="record.auditStatus !== 'DRAFT'" v-btn-permission="'bm_003_loo_02'">审批信息</a>
           
                        </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                       
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
            <ApprovalDetails
              :title="'审批详情'"
              :business-id="businessId"
              :visible="visibleApprove"
              @cancel="visibleApprove = false"
              @confirm="visibleApprove = false"
      />
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { stationList, eliminate, getMerchantCount } from '@/api/businessAffairs/postReporting'
import { getEmployees } from '@/api/businessAffairs/revenueAndCost'
import ApprovalDetails from '@/components/approvalDetails'
const columns = [
    // {
    //     title: '岗位责任书名称',
    //     dataIndex: 'name',
    // },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    // {
    //     title: '责任书类型',
    //     dataIndex: 'responsibilityTypeName',
    // },
    {
        title: '份数',
        dataIndex: 'size',
        minWidth: '70px'
    },
    {
        title: '签订完成日期',
        dataIndex: 'signFinishDate',
    },
    {
        title: '填报人',
        dataIndex: 'creatorName',
        minWidth: '90px'
    },
    {
        title: '填报时间',
        dataIndex: 'createTime',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
        // scopedSlots: { customRender: 'auditStatus' },
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectDepartment from '@/components/Select/SelectDepartment' // 部门
import SelectEmployees from '@/components/Select/SelectEmployees' // 人员
import Selector from '@/components/Select/Selector'
const searchArr = [
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },

    // {
    //     name: '所属部门',
    //     keyValue: 'projectId',
    //     valueKey: 'deptNameId',
    //     type: SelectDepartment,
    // },
    // {
    //     name: '责任书类型',
    //     type: Selector,
    //     valueKey: 'responsibllityTypeId',
    //     selectType: '20',
    //     urlType: 'commercial',
    // },
    // {
    //     name: '人员',
    //     value: 'employeeName',
    //     type: 'input',
    // },
    {
        name: '签订完成日期',
        value: 'privateDate',
        type: 'dateRange',
    },

    {
        name: '填报人',
        value: 'creatorName',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: 'PAST',
                label: '审批通过',
            },
            {
                value: 'SUBMITTED',
                label: '审批中',
            },
            {
                value: 'REJECTED',
                label: '审批不通过',
            },
            {
                value: 'DRAFT',
                label: '待提交审批',
            }
        ],
    },
]
import { STable } from '@/components'
export default {
    name:'a'+Date.now(),
    components: {
        SelectSubCompany,
        SelectProject,
        SelectDepartment,
        SelectEmployees,
        STable,
        ApprovalDetails,
    },

    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            visibleApprove: false,
            businessId: "",
            queryParam: {},
            countList:{},
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getMerchantCount(requestParameters)
                if (this.queryParam.startEndDate) {
                    requestParameters.createTimeBegin =
                        this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.createTimeEnd =
                        this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                if(this.queryParam.privateDate){
                    requestParameters.signBeginDate =
                        this.queryParam.privateDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.signEndDate =
                        this.queryParam.privateDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }

                return stationList(requestParameters).then((res) => {
                    console.log('数据返回对象：', res)
                    res.data.forEach(item => {
                    if(item.auditStatus=='PAST'){
                        item.auditStatusName='审批通过'
                    }else if(item.auditStatus=='SUBMITTED'){
                        item.auditStatusName='审批中'
                    }else if(item.auditStatus=='REJECTED'){
                        item.auditStatusName='审批不通过'
                    }else if(item.auditStatus=='DRAFT'){
                        item.auditStatusName='待提交审批'
                    }
                });
                    return res
                })
                
            },
            temp: () => {
            return (
                <span style="margin-right: 12px">
                待提交：<span class="totalNum">{ this.countList.waitCommitCnt }  </span> 个
                审批中：<span class="totalNum">{this.countList.reviewingCnt }  </span> 个
                审批通过：<span class="totalNum">{this.countList.reviewPassCnt}  </span> 个
                审批不通过：<span class="totalNum">{this.countList.rejectCnt }  </span> 个
                
                </span>
            )
          },
        }
    },
    methods: {
        handleApproveDetail(record) {
        this.visibleApprove = true
        this.businessId = record.id
      },
        // 统计
        getMerchantCount(requestParameters){
            getMerchantCount(requestParameters).then(res=>{
            if (res.code === 200) {
                this.countList=res.data
              }
          })
        },
        //搜索
        search(value) {
            // console.log(value)
            this.queryParam = value
            this.$refs.table.refresh(true)
        },

        // 收起展开
        toggleAdvanced() {
            this.advanced = !this.advanced
        },
        //新增
        handleAdd() {
            this.$router.push('/businessAffairs/postReporting/newIncrease')
        },
        // 查看
        detailed(e) {
            this.$router.push({
                path: '/businessAffairs/postReporting/detailed',
                query: { id: e.id, type: 'view' },
            })
        },
        //编辑
        addEdit(e, val) {
            this.$router.push({
                path: '/businessAffairs/postReporting/newIncrease',
                query: { id: e.id, auditStatus:e.auditStatus, t: val },
            })
        },

        // 删除草稿
        deleteDraft(e) {
            let that = this
            that.$confirm({
               title:"温馨提示",
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return eliminate({ id: e.id })
                        .then((res) => {
                            that.$message.success('删除成功！')
                            that.$refs.table.refresh(true)
                        })
                        .catch((res) => {
                            that.$message.warning('删除失败！')
                        })
                },
            })
        },
        // // 删除
        // deleteDraft(e) {
        //     eliminate({id:e.id}).then((res) => {
        //         if (res.data.code === 200) {
        //             this.$message.success('删除成功')
        //           this.$refs.table.refresh(true)
        //         } else {
        //             this.$message.error('删除失败')
        //         }
        //     })
        // },
    },
}
</script>

<style lang="less" scoped>
@deep: ~'>>>';
.tool-pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}
</style>

